import java.util.*;

public class test {
  public static void main(String[] args) {
    //
int[] num = {1,2,3,4,5,6,7,8,4,5,7,8};

      List<Integer> duplicates = findDuplicates(num);
    for (Integer duplicate : duplicates) {
      //
      System.out.println(duplicate);
    }
  }

  public static int findRepeatNumber(int[] nums){
      Set<Integer> set = new HashSet<>();
    for (int num : nums) {
        if (set.contains(num)){
            return num;
        }
        set.add(num);
    }
      return -1;
  }


    public static List<Integer> findDuplicates(int[] nums) {
      List list = new ArrayList();
    for (int i = 0; i < nums.length; i++) {
       if (nums[i] == nums[i+1])
       {
           list.add(nums[i]);
       }
      //
    }
        return list;
    }
}
